package presentation;

import javax.swing.JFrame;

public class PasswordChangeModel {
	
	private PasswordChangeFrame passwordChangeFrame;
	
	public PasswordChangeModel(JFrame frame) {
		passwordChangeFrame = new PasswordChangeFrame();
		passwordChangeFrame.setLocationRelativeTo(frame);
		passwordChangeFrame.setVisible(true);
	}
	
	public String getPassword() {
		while (true) {
			try {
				Thread.sleep(100);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			DialogEvent event = passwordChangeFrame.getEvent();
			if (event == null) {
				continue;
			}
			if (event == DialogEvent.CANCEL) {
				return null;
			}
			if (event == DialogEvent.CONFIRM) {
				return passwordChangeFrame.getPassword();
			}
		}
	}

	public void disposeFrame() {
		passwordChangeFrame.dispose();
	}

}
